package com.gxa.servlet.Statis;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.pojo.Result;
import com.gxa.pojo.Statistic.StatisticSell;
import com.gxa.pojo.staff.UserStaff;
import com.gxa.service.Statistic.StatisticService;
import com.gxa.service.Statistic.impl.StatisticServiceimpl;
import com.gxa.service.staffservice.StaffService;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@WebServlet("/statisticServlet")
public class StatisticSelectServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       request.setCharacterEncoding("utf-8");
       response.setContentType("text/json;charset=utf-8");
        String year = request.getParameter("year");
        String mouth = request.getParameter("mouth");
        String time=year+"_"+mouth+"%";
        StatisticService statisticService = new StatisticServiceimpl();
        List<StatisticSell> s = statisticService.selectyears(time);

        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        if (s!=null ){
            objectObjectHashMap.put("Result", Result.ok("查询成功",s));
        }else {
            objectObjectHashMap.put("Result",Result.error());
        }
        String s1 = JSON.toJSONString(objectObjectHashMap);
        response.getWriter().write(s1);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
